<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"prefix="fmt" %>

<!DOCTYPE HTML>
<html lang="cn">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<%@ include file="../include/include.jsp"%>

<script type="text/javascript">
	$(function() {
	    $("textarea[maxlength]").keyup(function() {
	        var area = $(this);
	        var max = parseInt(area.attr("maxlength"), 10);
	        if (max > 0) {
	            if (area.val().length > max) { 
	                area.val(area.val().substr(0, max)); 
	            }
	        }
	    });
	    $("textarea[maxlength]").blur(function() {
	        var area = $(this);
	        var max = parseInt(area.attr("maxlength"), 10); 
	        if (max > 0) {
	            if (area.val().length > max) { 
	                area.val(area.val().substr(0, max)); 
	            }
	        }
	    });
	}); 
	
	// 删除私信
	var deletePrivete = function (liId,letterId) {
		$('#' + liId).slideUp();
		$.post('letter_letter_deleteLetter.htm',{letterId:letterId});
	};
	
	var userPhoto = '${user.userPhoto}';
	
	var userId = '${user.userId}';
	
	if('' == userPhoto) {
		userPhoto = './images/feground/user.jpg';
	} else {
		
	}
	// 发送私信
	var sendPrivete = function() {
		if(com.tietiao.Validator.isEmptyStr($("#txa-message").attr("value"))) {
			com.tietiao.timeAlert('信息不能为空...',1,true);
			return;
		}
		$.post('letter_letter_sendLetter.htm',$('#send_letter_form').serialize(),function(data) {
			
			 var jsonData = eval('('+ data +')');
			
			 $("#txa-message").attr("value","");
			 var str = '<li class="me-msg-item" id="priv_lett_'+jsonData.id+'" style="display:none">';
				    str += '<div class="right-avatar r">';
				    str +=	'<a href="/people/1723893259/"><img  width="48" height="48" src="${rootPicPath}'+ userPhoto +'"></a>';
				    str +='</div>';
					str +='<div class="msg-contentr msg-forsome pr">';
					str +='<div class="msg-conn">';
					str +=	'<p>';
					str +=		jsonData.contents;
					str +=	'</p>';
					str +=	'<span><i>'+jsonData.time +'</i><u><br><a class="graylk" data-confirm="/people/msg/del/757990/" href="javascript:deletePrivete(\'priv_lett_'+jsonData.id+'\',\''+jsonData.id+'\')">删除</a></u></span>';
					str +='</div>';
					str +='<b class="msg-arrow-r msg-foright pa"></b>';
					str +='</div>';
					str +='</li>';
			$(str).insertBefore('#allmsglist li:first');
			$('#priv_lett_'+ jsonData.id ).slideDown();
		 });
	};
</script>

<title>我的私信</title>
</head>
<body style="overflow: inherit;" class="wider no-subnav catalog-lists">
<c:import url="/jsp/fg/include/default_head.jsp">
	<c:param name="menu" value="8" />
</c:import>
<!-- / header -->

<div class="container ">
	<div class="wrapper-content left-sidebar">
		<div id="content">
			<div class="wrapper-content-title">
				<span>与${friendUser.petName }的私信</span>
			</div>
			<div class="person-lists">
			</div>
			<div id="msg-reply" class="msg-reply clr" style="height:100px">
				<div class="msg-text pr l">
					<form  id="send_letter_form">
						<input type="hidden" name="friendUserId" value="${friendUser.userId }">
						<textarea class="msg-txa sffocus jqPlaceholde" placeholder="请输入您要发的私信内容...." maxlength="1000" name="content" id="txa-message" style="overflow: hidden; height: 57px;"></textarea>
						<div class="msg-subtn pa">
							<a href="javascript:;" target="_self" class="abtn abtn-s">
							<button type="button" onclick="sendPrivete()" class="button sign">发送</button>
							</a>
						</div>
						<b class="msg-arrow-r pa"></b>
					</form>
				</div>
				<div class="right-avatar r">
					<img width="48" height="48" src="${rootPicPath }${user.userPhoto}" >
				</div>
			</div>
			<ul id="allmsglist">
				<c:forEach items="${privateLetters}" var="item" >
					<c:choose>
						<c:when test="${item.sendId == friendUser.userId }" >
							<li class="re-msg-item clr" id="priv_lett${item.id }">
								<div class="left-avatar l">
									<a href="friend_friends_home.htm?userId=${item.sendId}" target="_blank"><img width="48" height="48" src="${rootPicPath }${friendUser.userPhoto}"></a>
								</div>
								<div class="msg-contentl msg-forsome pr">
									<div class="msg-conn">
										<p>
										<div style="line-height:1.8;color:#333">
											${item.contents }
										</div>
										</p>
										<span><i><fmt:formatDate value="${item.sendTime }" type="both" /></i><u><br><a class="graylk" data-confirm="/people/msg/del/757990/" href="javascript:deletePrivete('priv_lett${item.id }','${item.id}')">删除</a></u></span>
									</div>
									<b class="msg-arrow-l pa"></b>
								</div>
							</li>
						</c:when>
						<c:otherwise>
							<li class="me-msg-item" style="display: list-item;" id="priv_lett${item.id }">
								<div class="right-avatar r">
									<a href="friend_friends_home.htm?userId=${user.userId}" target="_blank"><img width="48" height="48" src="${rootPicPath }${user.userPhoto}"></a>
								</div>
								<div class="msg-contentr msg-forsome pr">
									<div class="msg-conn">
										<p>
											${item.contents }
										</p>
										<span><i><fmt:formatDate value="${item.sendTime }" type="both" /></i><u><br><a id="new_del835738" href="javascript:deletePrivete('priv_lett${item.id }','${item.id}')" class="graylk">删除</a></u></span>
									</div>
									<b class="msg-arrow-r msg-foright pa"></b>
								</div>
							</li>
						</c:otherwise>
					</c:choose>
				</c:forEach>
				
			</ul>
		</div>
		<!-- / content -->
		<div id="sidebar">
			<ul class="vtab">
				<li class="vtab-selected">
					<a href="#">私信</a>
				</li>
			</ul>
		</div>
		<!-- / sidebar -->
		
	</div>
	<!-- / wrapper-content -->
	<c:import url="/jsp/fg/include/default_foot.jsp"></c:import>
	<!-- / footer --> 
	
</div>
<!-- / container --> 

<div id="fb-root"> </div>
</body>
</html>